<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
use Tymon\JWTAuth\Contracts\JWTSubject;

class User extends Authenticatable implements JWTSubject
{
    use HasApiTokens,Notifiable;
    protected $guarded = [];

    protected $hidden = [
        'password', 'remember_token',
    ];

    protected $casts=[
      'profile_visibility'=>'boolean'
    ];

    /**
     * Created by zengwei.
     * Date: 2019/10/15
     * Time: 10:12
     * Function:关联的喜欢的cafe店
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     *
     */
    public function likes(){
        return $this->belongsToMany(Cafe::class,'users_cafes_likes','user_id','cafe_id');
    }

    public function getAuthIdentifier()
    {
        return $this->getKey();
    }

    public function findForPassport($username){
        return $this->where('account',$username)->orWhere('email',$username)->first();
    }

    public function getJWTCustomClaims()
    {
        // TODO: Implement getJWTCustomClaims() method.
        return [];
    }

    public function getJWTIdentifier()
    {
        // TODO: Implement getJWTIdentifier() method.
        return $this->getKey();
    }

    public function cafePhotos(){
        return $this->hasMany(CafesPhoto::class,'uploaded_by','id');
    }

    public function companies(){
        return $this->belongsToMany(Company::class,'company_owners','user_id','company_id');
    }
}
